<template>
  <div class="login-container">
    <!-- 登录 -->
    <div class="login-wrap">
      <div class="login">
        <div class="loginform">
          <ul class="tab clearFix">
            <li>
              <a href="##" class="current">登录</a>
            </li>
          </ul>

          <div class="content">
            <div class="form">

              <div class="input-text clearFix">
                <span></span>
                <input type="text" placeholder="请输入你的手机号" v-model="phone" name="phone"
                  v-validate="{ required: true, regex: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/ }"
                  :class="{ invalid: errors.has('phone') }" />
                <!-- <p class="error-msg">{{ errors.first('phone') + 1111111 }}</p> -->
                <p class="error-msg">{{ errors.first('phone') }}</p>

              </div>


              <div class="input-text clearFix">
                <span class="pwd"></span>
                <input type="password" placeholder="请输入你的6-20位的密码" v-model="password" name="password"
                  v-validate="{ required: true, regex: /^[0-9A-Za-z@.]{6,20}$/ }"
                  :class="{ invalid: errors.has('password') }">
                <p class="error-msg2">{{ errors.first('password') }}</p>

              </div>


              <div class="setting clearFix">
                <!-- <label class="checkbox inline">
                  <input name="m1" type="checkbox" value="2" checked="">
                  自动登录
                </label> -->
                <router-link class="register" to="/register">立即注册</router-link>
                <span class="forget">忘记密码？</span>
              </div>
              <button class="btn" @click.prevent="userLogin">登&nbsp;&nbsp;录</button>

            </div>

          </div>
        </div>
      </div>
    </div>
    <!-- 底部 -->
    <div class="copyright">
      <ul>
        <li>关于我们</li>
        <li>联系我们</li>
        <li>联系客服</li>
        <li>商家入驻</li>
        <li>营销中心</li>
        <li>手机蚂蚁</li>
        <li>销售联盟</li>
        <li>蚂蚁社区</li>
      </ul>
      <!-- <div class="address">地址：北京市昌平区宏福科技园综合楼6层</div> -->
      <!-- <div class="beian">京ICP备19006430号</div> -->
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      phone: '',
      password: '',
    }
  },
  methods: {
    //登录的回调函数
    async userLogin() {
      //登录成功
      const { phone, password } = this;
      const success = await this.$validator.validateAll();
      if (success) {
        await this.$store.dispatch('userLogin', { phone, password });
        // 登录路由组件：看路由中是否有query参数，有则跳转到query参数指定理由，无则跳转到主页
        let toPath = this.$route.query.redirect || '/home'
        this.$router.push(toPath);
      }

    },
  },
}
</script>

<style lang="less" scoped>
.login-container {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  .login-wrap {
    height: 600px;
    background-color: #4a5d95;
    position: relative;
    .login {
      width: 1200px;
      height: 100%;
      margin: 0 auto;
      background: url(./images/loginbg.png) no-repeat;
    }

    .loginform {
      width: 300px;
      box-sizing: border-box;
      background: #fff;
      top:50%;
      right: 20%;
      transform: translate(0,-50%);
      position: absolute;
      padding: 20px;

      .tab {

        li {
          width: 100%;
          float: left;
          text-align: center;

          a {
            width: 100%;
            display: block;
            height: 50px;
            line-height: 50px;
            font-size: 20px;
            font-weight: 700;
            color: #333;
            border: 1px solid #ddd;
            box-sizing: border-box;
            text-decoration: none;
            // color: #e1251b;
            color: #4cb9fc;

          

          }

        }
      }

      .content {
        width: 260px;
        box-sizing: border-box;
        border: 1px solid #ddd;
        border-top: none;
        padding: 18px;

        .form {
          margin: 15px 0 18px 0;
          font-size: 12px;
          line-height: 18px;
          height: ;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
           .input-text {
            margin-bottom: 25px;

            span {
              float: left;
              width: 37px;
              height: 32px;
              border: 1px solid #ccc;
              background: url(../../assets/images/icons.png) no-repeat -10px -201px;
              box-sizing: border-box;
              border-radius: 2px 0 0 2px;
            }

            .pwd {
              background-position: -72px -201px;
            }

            input {
              width: 180px;
              height: 32px;
              box-sizing: border-box;
              border: 1px solid #ccc;
              border-left: none;
              float: left;
              padding-top: 6px;
              padding-bottom: 6px;
              font-size: 14px;
              line-height: 22px;
              padding-right: 8px;
              padding-left: 8px;

              border-radius: 0 2px 2px 0;
              outline: none;
            }

            .error-msg {
              position: absolute;
              top: 38%;
              color: red;
            }

            .error-msg2 {
              position: absolute;
              top: 55%;
              color: red;
            }
          }



          .setting {
            .register {
              float: left;
              font-size: 15px;
              // line-height: 38px;
            }

            .register:hover {
              color: #4cb9fc;
              text-decoration: underline;
            }

            .forget {
              font-size: 15px;
              float: right;
            }
          }

          .btn {
            background-color: #e1251b;
            background-color: #4cb9fc
;
            padding: 6px;
            border-radius: 0;
            font-size: 16px;
            font-family: 微软雅黑;
            word-spacing: 4px;
            border: 1px solid #4cb9fc;
            color: #fff;
            width: 100%;
            height: 36px;
            margin-top: 25px;
            outline: none;
            cursor: pointer;
          }

        }

        .call {
          margin-top: 30px;

          ul {
            float: left;

            li {
              float: left;
              margin-right: 5px;
            }
          }


        }

      }
    }
  }

  .copyright {
    width: 1200px;
    margin: 0 auto;
    text-align: center;
    line-height: 24px;

    ul {
      li {
        display: inline-block;
        border-right: 1px solid #e4e4e4;
        padding: 0 20px;
        margin: 15px 0;
      }
    }
  }

}
</style>